﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddEdit.aspx.cs" Inherits="CardLogistics.Web.MainPage.CardRecovery.ReturnBadCard.AddEdit" %>
<%@ Register Src="../../../Controls/WebUserControl_Nav.ascx" TagName="WebUserControl_Nav" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>退换坏卡回收-新增/编辑</title>
    <link href="../../../css/style.css" rel="stylesheet" type="text/css" />
    <link href="../../../css/selPage.css" rel="stylesheet" type="text/css" />
    <script src="../../../js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="../../../js/valReq.js" type="text/javascript"></script>
    <script src="../../../js/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../../../js/jquery.tipswindow.2.0.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        function valReq(issubmit) {
            //非空校验
            var altStr = valid_isempty('RETURNCARDNO', '退货单号');
            altStr += valid_isempty('PConNo', '合同编号');
            altStr += valid_isempty('RETURNDATA', '退货日期');
            //非数字或字母校验
            altStr += valid_isnoCh('RETURNCARDNO', '退货单号');
            altStr += GetCardInfo();
            altStr += valid_isempty('hf_CheckId', '退货明细');
            if (altStr != "") {
                alert(altStr);
                return false;
            }
            else {
                if (issubmit == 1) {
                    if (confirm("提交后该信息进入待审批状态不可编辑,确认提交吗?") == true) {
                        return true;
                    }
                    else
                        return false;
                }
                else
                    return true;
            }
        }

        function GetCardInfo() {
            var Data_value = [];
            var errInfo = ""; //返回错误消息
            var vIndex = 0;
            var DueNum = 0; //应有数量
            var ActualNum = 0; //实际数量

            var BoxNo = $("input[name=BoxNo]");
            var CardNo = $("input[name=CardNo]");
            var StartNo = $("input[name=StartNo]");
            var EndNo = $("input[name=EndNo]");
            var DueNumbers = $("input[name=DueNumbers]");
            var ActualNumber = $("input[name=ActualNumber]");
            var MissingCardNo = $("input[name=MissingCardNo]");

            $("select[name='CardNo'] option:selected").each(function (i, o) {
                if (Trim($(o).text()) != "") {
                    Data_value[vIndex] = "'" + Trim($(BoxNo[i]).val()) + "'|'" + Trim($(o).text()) + "'|'" + Trim($(StartNo[i]).val())
                    + "'|'" + Trim($(EndNo[i]).val()) + "'|" + Trim($(DueNumbers[i]).val()) + "|" + Trim($(ActualNumber[i]).val()) + "|" + "'" + Trim($(MissingCardNo[i]).val()) + "'"; //字段值
                    vIndex++;
                    if (Trim($(o).val()) == "" || $(CardNo[i]).val() == "0")
                        errInfo += "第" + vIndex + "行明细不能为空\n";
                }
            });
            $("#hf_CheckId").val(Data_value.join(";"));
            //实际数量赋值给隐藏值，便于后台判断是否大于需求单数量
            document.getElementById("CurrCardTotal").value = GetSumByName("ActualNumber");
            return errInfo;
        }
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#PConNo").click(function () {//选择合同单
                $.tipsWindow({
                    ___title: "选择合同批次",
                    ___content: "iframe:../../SelectPage/SelReturnBadCard.aspx?type=cardret",
                    ___width: "1000",
                    ___height: "500",
                    ___drag: "___boxTitle",
                    ___showbg: true
                });
            });
        })
    </script>
    <script type="text/javascript">
        //合计
        $(document).ready(function () {
        });

        function BindDetailInfo() {
            var DueNum = 0; //应有数量
            var ActualNum = 0; //实际数量
            var BoxNo = $("input[name=BoxNo]");
            var CardNo = $("select[name=CardNo]");
            var StartNo = $("input[name=StartNo]");
            var EndNo = $("input[name=EndNo]");
            var DueNumbers = $("input[name=DueNumbers]");
            var ActualNumber = $("input[name=ActualNumber]");
            var MissingCardNo = $("input[name=MissingCardNo]");
            var ids = document.getElementById("hf_CheckId").value;
            var str1 = ids.split(";");
            for (var i = 0; i < str1.length; i++) {
                if (str1[i] != "") {
                    $(BoxNo[i]).val(str1[i].split("|")[0].replace("'", "").replace("'", ""));
                    $(CardNo[i]).val(str1[i].split("|")[1].replace("'", "").replace("'", ""));
                    $(StartNo[i]).val(str1[i].split("|")[2].replace("'", "").replace("'", ""));
                    $(EndNo[i]).val(str1[i].split("|")[3].replace("'", "").replace("'", ""));
                    $(DueNumbers[i]).val(str1[i].split("|")[4]);
                    $(ActualNumber[i]).val(str1[i].split("|")[5]);
                    $(MissingCardNo[i]).val(str1[i].split("|")[6].replace("'", "").replace("'", ""));
                    DueNum += parseInt(str1[i].split("|")[4]);
                    ActualNum += parseInt(str1[i].split("|")[5]);
                }
            }

            GetSumInfo();
            document.getElementById("CurrCardTotal").value = GetSumByName("ActualNumber");

        }
        window.onload = function () {
            BindDetailInfo();
            SetInputRedonley("BoxNo|text-align:center,StartNo,EndNo,DueNumbers,ActualNumber,MissingCardNo");
            BindCardNO();
        }

        function BindCardNO() {
            if (('<%=IsEdit %>') == "False") {
                var sCardNO = $("select[name=CardNo]");
                for (var i = 0; i < sCardNO.length; i++) {
                    if (i >= sCardNO[i].children.length)
                        break;
                    sCardNO[i].selectedIndex = i + 1; //第一列为空，所以要+1
                    selCardNoInfo(sCardNO[i]);
                }
            }
        }
        //根据盒号获取入库详情信息
        function selCardNoInfo(obj) {
            var stxt = obj.options[obj.options.selectedIndex].text; //格式：ID,盒号
            var txtTmp = "";
            var snum = 0;
            $("select[name=CardNo] option:selected").each(function (i, o) {//所有选中的盒号集合
                if (Trim($(o).text()) != "") {
                    txtTmp += (Trim($(o).text())) + "|";
                    if ((Trim($(o).text())) == stxt)
                        snum++;
                }
            });
            var temp = obj.options[obj.options.selectedIndex].value; //格式：箱号|开始卡号|结束卡号|应有数量|实际数量|缺失卡号
            var tr = obj.parentNode.parentNode; //当前行
            if (snum > 1) {
                alert("盒号不可重复选择！");
                $(tr.cells[2]).find("select").val("");
            }
            if (temp.split('|').length == 6 && snum <= 1) {
                $(tr.cells[1]).find("input").val(temp.split('|')[0]);
                $(tr.cells[3]).find("input").val(temp.split('|')[1]);
                $(tr.cells[4]).find("input").val(temp.split('|')[2]);
                $(tr.cells[5]).find("input").val(temp.split('|')[3]);
                $(tr.cells[6]).find("input").val(temp.split('|')[4]);
                $(tr.cells[7]).find("input").val(temp.split('|')[5]);
                GetSumInfo();
                return;
            }
            $(tr.cells[1]).find("input").val("");
            $(tr.cells[3]).find("input").val("");
            $(tr.cells[4]).find("input").val("");
            $(tr.cells[5]).find("input").val("0");
            $(tr.cells[6]).find("input").val("0");
            $(tr.cells[7]).find("input").val("")
            GetSumInfo();
        }
        //求应有数量合计数量的和
        function GetSumInfo() {
            document.getElementById("td_DueSum").innerHTML = GetSumByName("DueNumbers");
            document.getElementById("td_ActualSum").innerHTML = GetSumByName("ActualNumber");
        }
    </script>
</head>
<body>
    <form id="frmFather" runat="server">
    <uc1:WebUserControl_Nav ID="WebUserControl_Nav1" runat="server" />
    <%=TitleName %>
    <asp:HiddenField ID="hf_CheckId" runat="server" />
    <input type="hidden" id="DemandTotal" runat="server" />
    <input type="hidden" id="CardOutTotal" runat="server" />
    <input type="hidden" id="CurrCardTotal" runat="server" />
    <input type="hidden" id="hfEditSumCard" runat="server" />
    <table class="theForm" width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="titleTxt">
                退货单号：
            </td>
            <td class="contentTxt">
                <input id="RETURNCARDNO" runat="server" type="text" class="dfinputNoEmp" maxlength="15" />
            </td>
            <td class="titleTxt">
                合同批次：
            </td>
            <td class="contentTxt">
                <input id="PConNo" runat="server" readonly="readonly" type="text" class="dfinputImg"
                    maxlength="25" onblur="javascript:CardType() " />
                <asp:HiddenField ID="hf_ConId" runat="server" />
                <asp:Button ID="BtnId" runat="server" OnClick="TypeValue_Click" Width="0px" />
            </td>
        </tr>
        <tr>
            <td class="titleTxt">
                合同信息：
            </td>
            <td class="contentTxt" colspan="3">
                <asp:Label ID="lblConInfo" runat="server" Text="&nbsp;请选择合同！"></asp:Label>
            </td>
        </tr>
        <tr>
            <td class="titleTxt">
                情况说明：
            </td>
            <td colspan="3">
                <input id="NOTE" runat="server" type="text" class="dfinput" style="width: 90%;" maxlength="200" />
            </td>
        </tr>
        <tr>
            <td class="titleTxt">
                退货日期：
            </td>
            <td class="contentTxt">
                <input id="RETURNDATA" runat="server" type="text" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" />
            </td>
            <td class="titleTxt">
                经办人：
            </td>
            <td class="contentTxt">
                <input id="ATTN" runat="server" type="text" class="dfinput" maxlength="25" />
            </td>
        </tr>
        <tr>
            <td class="titleTxt">
                备注：
            </td>
            <td colspan="3">
                <input id="REMARKS" runat="server" type="text" class="dfinput" style="width: 90%;"
                    maxlength="200" />
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <div class="ddetail" style="height: 270px;">
                    <table class="tabledetail" id="tb_Detail" style="text-align: center;">
                        <thead>
                            <tr>
                                <th style="width: 30px;">
                                    序号
                                </th>
                                <th style="width: 150px;">
                                    箱号
                                </th>
                                <th style="width: 150px;">
                                    盒号
                                </th>
                                <th style="width: 150px;">
                                    起始卡号
                                </th>
                                <th style="width: 150px;">
                                    结束卡号
                                </th>
                                <th style="width: 150px;">
                                    应有数量/张
                                </th>
                                <th style="width: 150px;">
                                    实际数量/张
                                </th>
                                <th style="width: 150px;">
                                    缺卡卡号
                                </th>
                                  <th>
                                    &nbsp;
                                </th>
                            </tr>
                        </thead>
                        <tbody id="tablebody">
                            <tr>
                                <td>
                                    1
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <select name="CardNo" onchange="selCardNoInfo(this)">
                                        <option value="0"></option>
                                        <%foreach (var cardNo in CardNOList)
                                          {%>
                                        <option value="<%=cardNo.Key %>">
                                            <%=cardNo.Value%></option>
                                        <% }%>
                                    </select>
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="DueNumbers" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" type="text" class="dfinput" />
                                </td>
                                  <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="30px">
                                    2
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <select name="CardNo" onchange="selCardNoInfo(this)">
                                        <option value="0"></option>
                                        <%foreach (var cardNo in CardNOList)
                                          {%>
                                        <option value="<%=cardNo.Key %>">
                                            <%=cardNo.Value%></option>
                                        <% }%>
                                    </select>
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="DueNumbers" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" type="text" class="dfinput" />
                                </td>
                                   <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="30px">
                                    3
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <select name="CardNo" onchange="selCardNoInfo(this)">
                                        <option value="0"></option>
                                        <%foreach (var cardNo in CardNOList)
                                          {%>
                                        <option value="<%=cardNo.Key %>">
                                            <%=cardNo.Value%></option>
                                        <% }%>
                                    </select>
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="DueNumbers" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" type="text" class="dfinput" />
                                </td>
                                   <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="30px">
                                    4
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <select name="CardNo" onchange="selCardNoInfo(this)">
                                        <option value="0"></option>
                                        <%foreach (var cardNo in CardNOList)
                                          {%>
                                        <option value="<%=cardNo.Key %>">
                                            <%=cardNo.Value%></option>
                                        <% }%>
                                    </select>
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="DueNumbers" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" type="text" class="dfinput" />
                                </td>
                                   <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="30px">
                                    5
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <select name="CardNo" onchange="selCardNoInfo(this)">
                                        <option value="0"></option>
                                        <%foreach (var cardNo in CardNOList)
                                          {%>
                                        <option value="<%=cardNo.Key %>">
                                            <%=cardNo.Value%></option>
                                        <% }%>
                                    </select>
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="DueNumbers" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" type="text" class="dfinput" />
                                </td>
                                   <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="30px">
                                    6
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <select name="CardNo" onchange="selCardNoInfo(this)">
                                        <option value="0"></option>
                                        <%foreach (var cardNo in CardNOList)
                                          {%>
                                        <option value="<%=cardNo.Key %>">
                                            <%=cardNo.Value%></option>
                                        <% }%>
                                    </select>
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="DueNumbers" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" type="text" class="dfinput" />
                                </td>
                                   <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="30px">
                                    7
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <select name="CardNo" onchange="selCardNoInfo(this)">
                                        <option value="0"></option>
                                        <%foreach (var cardNo in CardNOList)
                                          {%>
                                        <option value="<%=cardNo.Key %>">
                                            <%=cardNo.Value%></option>
                                        <% }%>
                                    </select>
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="DueNumbers" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" type="text" class="dfinput" />
                                </td>
                                   <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="30px">
                                    8
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <select name="CardNo" onchange="selCardNoInfo(this)">
                                        <option value="0"></option>
                                        <%foreach (var cardNo in CardNOList)
                                          {%>
                                        <option value="<%=cardNo.Key %>">
                                            <%=cardNo.Value%></option>
                                        <% }%>
                                    </select>
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="DueNumbers" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" type="text" class="dfinput" />
                                </td>
                                   <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="30px">
                                    9
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <select name="CardNo" onchange="selCardNoInfo(this)">
                                        <option value="0"></option>
                                        <%foreach (var cardNo in CardNOList)
                                          {%>
                                        <option value="<%=cardNo.Key %>">
                                            <%=cardNo.Value%></option>
                                        <% }%>
                                    </select>
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="DueNumbers" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" type="text" class="dfinput" />
                                </td>
                                   <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="30px">
                                    10
                                </td>
                                <td>
                                    <input name="BoxNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <select name="CardNo" onchange="selCardNoInfo(this)">
                                        <option value="0"></option>
                                        <%foreach (var cardNo in CardNOList)
                                          {%>
                                        <option value="<%=cardNo.Key %>">
                                            <%=cardNo.Value%></option>
                                        <% }%>
                                    </select>
                                </td>
                                <td>
                                    <input name="StartNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="EndNo" type="text" class="dfinput" />
                                </td>
                                <td>
                                    <input name="DueNumbers" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="ActualNumber" type="text" class="dfinput" value="0" />
                                </td>
                                <td>
                                    <input name="MissingCardNo" type="text" class="dfinput" />
                                </td>
                                   <td>
                                    &nbsp;
                                </td>
                            </tr>
                            <%=AddTr.ToString() %>
                        </tbody>
                    </table>
                </div>
                <table class="tablesum">
                    <tr>
                        <th width="40px">
                            &nbsp;
                        </th>
                        <th style="width: 150px;text-align: center;">
                            合计
                        </th>
                        <th style="width: 150px">
                            &nbsp;
                        </th>
                        <th style="width: 150px">
                            &nbsp;
                        </th>
                        <th style="width: 150px">
                            &nbsp;
                        </th>
                        <th style="width: 150px; text-align: right;" id="td_DueSum">
                            0
                        </th>
                        <th style="width: 150px; text-align: right;" id="td_ActualSum">
                            0
                        </th>
                        <th>
                            &nbsp;
                        </th>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="4" align="center" style="height: 55px;">
                <asp:Button ID="btn_Submit" CssClass="btn" runat="server" Text="保存并提交" OnClientClick="return valReq(1);"
                    OnClick="btn_Submit_Click" />
                <asp:Button ID="btn_Add" CssClass="btn" runat="server" Text="保存" OnClientClick="return valReq(0);"
                    OnClick="btn_Add_Click" />
                <input type="button" class="btn" value="返回" onclick="javascript:history.go(-1);" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
